package com.wenan.ui.reports
{
	import com.wenan.data.ParameterCollection;
	import com.wenan.ui.controls.charts.Histogram;
	
	import mx.collections.ArrayCollection;
	import mx.containers.Box;
	import mx.containers.VBox;
	import mx.controls.Alert;
	import mx.core.UIComponent;

	public class ThroughoutReportInfo extends ReportInfo
	{
		private var histogram:Histogram;
		private var _xField:String;
		private var _yField:String;
		
		public function ThroughoutReportInfo()
		{
			super();
		}
		
		public override function get title():String
		{
			return "柱状图";
		}

		public override function get xField():String
		{
			return _xField;
		}
		
		public override function set xField(value:String):void
		{
			_xField = value;
		}
		
		public function get yField():String
		{
			return _yField;
		}
		
		public function set yField(value:String):void
		{
			_yField = value;
		}
		
		
		public override function get yFields():Array
		{
			return [_yField];
		}
		
		public override function set yFields(array:Array):void
		{
			_yField = null;
			if (array != null && array.length > 0)
			{
				_yField = array[0];
			}
		}
		
		public override function createReportPanel():UIComponent {
			histogram = new Histogram();
			var chartSty:ParameterCollection = reportData.reportStyle;
			histogram.dataProvider = reportData.dataProvider;
			if (chartSty && chartSty.length > 0)
			{
				var charts:ParameterCollection =  chartSty.getObj("柱状图") as ParameterCollection;
				if (!charts)
				{
					Alert.show("找不到此报表的渲染信息！");
					return new Box();
				}
				histogram.listData = charts.getObj("ySelectableFields") as ArrayCollection;
				histogram.listLabelField = "title";
				
				histogram.categoryField = charts.getObj("xDefaultField") as String;
				histogram.title = (charts.getObj("yDefaultFields") as ArrayCollection).getItemAt(0).title;
				histogram.valueField = (charts.getObj("yDefaultFields") as ArrayCollection).getItemAt(0).propertyName;
				
				histogram.yDefaultData = (charts.getObj("yDefaultFields") as ArrayCollection);
				histogram.colors.addItem((charts.getObj("yDefaultFields") as ArrayCollection)[0].color);
				
				histogram.xHeading.title = charts.getObj("reportStyle").axisX;
				histogram.yHeading.title = charts.getObj("reportStyle").axisY;
				histogram.titleName = charts.getObj("reportStyle").title;
				histogram.titleSize = 20;
			}
		
			
			return histogram.createReportPanel();
		}
	}
}